package cn.itcast.java.jdbc;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.junit.Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * Author itcast
 * Date 2021/10/13 23:28
 * Desc TODO
 */
public class Demo01 {
    @Test
    public void demo02(){
        //修改
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            //conn = JdbcUtils.getConnection();
            ComboPooledDataSource cpd = new ComboPooledDataSource();
            conn = cpd.getConnection();
            st = conn.createStatement();
            rs = st.executeQuery("select * from category");
            while(rs.next()){

                System.out.println(rs.getInt(1));
                System.out.println(rs.getString(2));
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally{
            JdbcUtils.closeResource(conn, st, rs);
        }
    }
}
